package com.jetpack_sunflower.utils

import android.content.Context
import com.jetpack_sunflower.data.AppDataBase
import com.jetpack_sunflower.data.GardenPlantingRepository
import com.jetpack_sunflower.data.PlantRespository
import com.jetpack_sunflower.viewmodels.GardenPlantingListViewModelFactory
import com.jetpack_sunflower.viewmodels.PlantDetailViewModelFactory
import com.jetpack_sunflower.viewmodels.PlantListViewModelFactory

object InjectorUtils {

    private fun getPlantRepository(context: Context): PlantRespository {
        return PlantRespository.getInstance(AppDataBase.getInstance(context).getPlantDao())
    }

    private fun getGardenPlantRepository(context: Context): GardenPlantingRepository {
        return GardenPlantingRepository.getInstance(AppDataBase.getInstance(context).getGardenPlantingDao())
    }

    fun providePlantListViewModelFactory(context: Context): PlantListViewModelFactory {
        val plantRepository = getPlantRepository(context)
        return PlantListViewModelFactory(plantRepository)
    }

    fun providerPlantDetailViewModelFactory(context: Context, plantId: String): PlantDetailViewModelFactory {
        val plantRespository = getPlantRepository(context)

        val gardenPlantRepository = getGardenPlantRepository(context)
        return PlantDetailViewModelFactory(plantRespository, gardenPlantRepository, plantId)
    }

    fun provideGardenPlantingListViewModelFactory(
            context: Context
    ): GardenPlantingListViewModelFactory {
        val repository = getGardenPlantRepository(context)
        return GardenPlantingListViewModelFactory(repository)
    }


}